define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'site/index',
                    add_url: 'site/add',
                    edit_url: 'site/edit',
                    del_url: 'site/del',
                    multi_url: 'site/multi',
                    table: 'site',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'organization_id', title: __('Organization_id'), visible:false, searchList: {"5":__('Organization_id 5')}},
                        // {field: 'organization_id_text', title: __('Organization_id'), operate:false},
                        {field: 'building_name', title: __('Building_name')},
                        {field: 'building_alias', title: __('Building_alias')},
                        {field: 'building_customer_type', title: __('Building_customer_type'), visible:false, searchList: {"1":__('Building_customer_type 1')}},
                        {field: 'building_customer_type_text', title: __('Building_customer_type'), operate:false},
                        {field: 'building_customer_name', title: __('Building_customer_name')},
                        {field: 'building_project_name', title: __('Building_project_name')},
                        {field: 'building_project_address', title: __('Building_project_address')},
                        {field: 'building_begin_time', title: __('Building_begin_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'building_end_time', title: __('Building_end_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'building_amount', title: __('Building_amount'), operate:'BETWEEN'},
                        {field: 'building_contract_number', title: __('Building_contract_number')},
                        {field: 'building_amount_paid', title: __('Building_amount_paid'), operate:'BETWEEN'},
                        {field: 'building_amount_paid_rate', title: __('Building_amount_paid_rate')},
                        {field: 'building_status', title: __('Building_status'), visible:false, searchList: {"1":__('Building_status 1')}},
                        {field: 'building_status_text', title: __('Building_status'), operate:false},
                        // {field: 'building_sheet', title: __('Building_sheet'), visible:false, searchList: {"2":__('Building_sheet 2')}},
                        // {field: 'building_sheet_text', title: __('Building_sheet'), operate:false},
                        // {field: 'building_operator_user_id', title: __('Building_operator_user_id')},
                        {field: 'building_operator_user_name', title: __('Building_operator_user_name')},
                        // {field: 'building_add_user_id', title: __('Building_add_user_id')},
                        {field: 'building_add_user_name', title: __('Building_add_user_name')},
                        {field: 'building_create_time', title: __('Building_create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'building_info', title: __('Building_info')},
                        {field: 'building_is_encore', title: __('Building_is_encore'), visible:false, searchList: {"1":__('Building_is_encore 1')}},
                        {field: 'building_is_encore_text', title: __('Building_is_encore'), operate:false},
                        // {field: 'building_delete', title: __('Building_delete'), visible:false, searchList: {"1":__('Building_delete 1')}},
                        // {field: 'building_delete_text', title: __('Building_delete'), operate:false},
                        // {field: 'last_update_user_id', title: __('Last_update_user_id')},
                        {field: 'last_update_user_name', title: __('Last_update_user_name')},
                        {field: 'last_update_time', title: __('Last_update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            // 创建者名称、工地名称记录到隐藏域中提交
            $(".form-group").on("blur", ".selectpage", function () {
                $('#' + $(this).attr('id') + '_value').val($(this).val())
            });

            Controller.api.bindevent();
        },
        edit: function () {
            // 创建者名称、工地名称记录到隐藏域中提交
            $(".form-group").on("blur", ".selectpage", function () {
                $('#' + $(this).attr('id') + '_value').val($(this).val())
            });

            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});